let App = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rel: [
     
    ],
    use_time: 60,
    total: 0,
    percent: 0,
    scrollTop: 0,
    yes_num:0,
    time_second:0
  },
  goTop: function(t) {
    this.setData({
      scrollTop: 0
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (typeof options.show_arr == 'undefined') {
      return false;
    }
    let rr = JSON.parse(options.show_arr);
    let yesNum = 0;
    rr.forEach((item) => {
      if (item.hid_val == item.val) {
        yesNum++;
      }
    });
    let t = rr.length;
    if (t == 0) {
      t = 1;
    }
    let pp = ((yesNum / t) * 100).toFixed(2);

    that.setData({
      'rel': rr,
      'total': rr.length,
      'use_time': that.changeUseTime(options.use_time),
      'percent': pp,
      'yes_num':yesNum,
      'time_second':options.use_time
    })
    that.createSubtract(options.show_arr);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  //生命周期函数--监听页面初次渲染完成
  onReady: function (e) {
    var that = this;
    //请求数据

  },

  //滑动事件
  bindChange: function (e) {
    model.updateAreaData(this, 1, e);
    item = this.data.item;
    this.setData({
      province: item.provinces[item.value[0]].name,
      city: item.citys[item.value[1]].name,
      county: item.countys[item.value[2]].name
    });
  },
  onReachBottom: function () {},
  nono: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    console.log('down')
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  createSubtract(arr_str) {
    var that = this;

    App._post_form('study/create_subtract', {
      arr_str: arr_str,
      total: that.data.total,
      time_second: that.data.time_second,
      percent: that.data.percent,
      yes_num:that.data.yes_num
    }, function (res) {


    }, function () {
      wx.hideLoading({
        success: (res) => {
          setTimeout(function () {
            wx.navigateBack({

            })
          }, 2000)
        },
      })
    }, function () {
      wx.hideLoading({
        success: (res) => {

        },
      })
    })


  },
  changeUseTime(time) {
    if (typeof time == 'undefined' || time == '' || time == "0") {
      return 0;
    }
  
    var secondTime = parseInt(time); // 秒
    var minuteTime = 0; // 分
    var hourTime = 0; // 小时
    if (secondTime >= 60) {
      minuteTime = parseInt(secondTime / 60);
      secondTime = parseInt(secondTime % 60);
      if (minuteTime >= 60) {
        hourTime = parseInt(minuteTime / 60);
        minuteTime = parseInt(minuteTime % 60);
      }
    }
    var result = "" + (parseInt(secondTime) < 10 ? "0" + parseInt(secondTime) : parseInt(secondTime));

    if (minuteTime > 0) {
      result = "" + (parseInt(minuteTime) < 10 ? "0" + parseInt(minuteTime) : parseInt(minuteTime)) + ":" + result;
    }
    if (hourTime > 0) {
      result = "" + (parseInt(hourTime) < 10 ? "0" + parseInt(hourTime) : parseInt(hourTime)) + ":" + result;
    }
    result = "" + hourTime + "时" + minuteTime + "分" + secondTime + "秒";
    console.log(result)
    return result;
  }
})